//
//  ComentPieCell.m
//  test
//
//  Created by 朱圳 on 2018/3/12.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "ComentPieCell.h"
@interface ComentPieCell()<ZFPieChartDelegate,ZFPieChartDataSource>

@end
@implementation ComentPieCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)createUI{
    
    ZFPieChart *pie = [[ZFPieChart alloc]init];
    pie.userInteractionEnabled = NO;
    pie.delegate = self;
    pie.dataSource = self;
    pie.isShowPercent = YES;
    pie.piePatternType = kPieChartPatternTypeCircle;
    [self.contentView addSubview:pie];
    [pie mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 100));
        [make.top.mas_equalTo(self) setOffset:80];
        make.centerX.mas_equalTo(self);
    }];    
    self.pie = pie;
    UILabel *la = [[UILabel alloc]init];
    la.backgroundColor = ZFColor(116, 197, 248, 1);
    [self.contentView addSubview:la];
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
       [make.right.mas_equalTo(self.mas_right) setOffset:-ScreenWidth/3];
        make.size.mas_equalTo(CGSizeMake(12, 12));
        [make.top.mas_equalTo(self.mas_top) setOffset:30];
    }];

    UILabel *lacon = [[UILabel alloc]init];
    lacon.text = @"80% 卓越";
    lacon.font = [UIFont systemFontOfSize:12];
    lacon.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lacon];
    [lacon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.left.equalTo(la.mas_right).offset(10);
        make.bottom.equalTo(la.mas_bottom).offset(3);
        
    }];
    self.zy = lacon;

    UILabel *la1 = [[UILabel alloc]init];
    la1.backgroundColor = ZFColor(244, 184, 96, 1);
    [self.contentView addSubview:la1];
    [la1 mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.right.mas_equalTo(self.mas_right) setOffset:-ScreenWidth/3];
        make.size.mas_equalTo(CGSizeMake(12, 12));
       [make.top.mas_equalTo(self.mas_top) setOffset:50];
    }];

    UILabel *lacon1 = [[UILabel alloc]init];
    lacon1.text = @"15.87% 非常满意";
    lacon1.font = [UIFont systemFontOfSize:12];
    lacon1.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lacon1];
    [lacon1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.left.equalTo(la1.mas_right).offset(10);
        [make.top.mas_equalTo(self.mas_top) setOffset:50];
    }];
    self.fmy = lacon1;
    
    UILabel *la2 = [[UILabel alloc]init];
    la2.backgroundColor = ZFColor(238, 124, 108, 1);
    [self.contentView addSubview:la2];
    [la2 mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.right.mas_equalTo(self.mas_right) setOffset:-ScreenWidth/3];
        make.size.mas_equalTo(CGSizeMake(12, 12));
        [make.top.mas_equalTo(self.mas_top) setOffset:70];
    }];

    UILabel *lacon2 = [[UILabel alloc]init];
    lacon2.text = @"6.97% 满意";
    lacon2.font = [UIFont systemFontOfSize:12];
    lacon2.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lacon2];
    [lacon2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.left.equalTo(la2.mas_right).offset(10);
        [make.top.mas_equalTo(self.mas_top) setOffset:70];
    }];
    self.my = lacon2;
    
    UILabel *la3 = [[UILabel alloc]init];
    la3.backgroundColor = ZFColor(120, 218, 116, 1);
    [self.contentView addSubview:la3];
    [la3 mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.right.mas_equalTo(self.mas_right) setOffset:-ScreenWidth/3];
        make.size.mas_equalTo(CGSizeMake(12, 12));
        [make.top.mas_equalTo(self.mas_top) setOffset:90];
    }];

    UILabel *lacon3 = [[UILabel alloc]init];
    lacon3.text = @"0.82% 一般";
    lacon3.font = [UIFont systemFontOfSize:12];
    lacon3.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lacon3];
    [lacon3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.left.equalTo(la3.mas_right).offset(10);
        [make.top.mas_equalTo(self.mas_top) setOffset:90];
    }];
    self.yb = lacon3;
    
    UILabel *la4 = [[UILabel alloc]init];
    la4.backgroundColor = ZFColor(252, 242, 100, 1);
    [self.contentView addSubview:la4];
    [la4 mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.right.mas_equalTo(self.mas_right) setOffset:-ScreenWidth/3];
        make.size.mas_equalTo(CGSizeMake(12, 12));
        [make.top.mas_equalTo(self.mas_top) setOffset:110];
    }];

    UILabel *lacon4 = [[UILabel alloc]init];
    lacon4.text = @"0% 差评";
    lacon4.font = [UIFont systemFontOfSize:12];
    lacon4.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lacon4];
    [lacon4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(100);
        make.left.equalTo(la4.mas_right).offset(10);
        [make.top.mas_equalTo(self.mas_top) setOffset:110];
    }];
    self.cp = lacon4;
}

- (CGFloat)radiusForPieChart:(ZFPieChart *)pieChart {
     return 70.f;
}

- (NSArray *)colorArrayInPieChart:(ZFPieChart *)pieChart {
        return @[ZFColor(116, 197, 248, 1), ZFColor(244, 184, 96, 1), ZFColor(238, 124, 108, 1),ZFColor(120, 218, 116, 1),ZFColor(252, 242, 100, 1)];
}
- (CGFloat)allowToShowMinLimitPercent:(ZFPieChart *)pieChart{
    return 5.f;
}
- (NSArray *)valueArrayInPieChart:(ZFPieChart *)pieChart {
     return self.starCountArr;
}

-(void)setModel:(QuestionsModel *)model{
    _model = model;
    self.starCountArr = _model.starCountArr;
    
    double total = [_model.starCountArr[0] doubleValue] + [_model.starCountArr[1] doubleValue]+ [_model.starCountArr[2] doubleValue]+ [_model.starCountArr[3] doubleValue]+ [_model.starCountArr[4] doubleValue];
    double zy = [_model.starCountArr[0] doubleValue] / total*100;
    self.zy.text = [NSString stringWithFormat:@"%.2f%% 卓越",zy];
    
    double fmy = [_model.starCountArr[1] doubleValue] / total*100;
    self.fmy.text = [NSString stringWithFormat:@"%.2f%% 非常满意",fmy];
    
    double my = [_model.starCountArr[2] doubleValue] / total*100;
    self.my.text = [NSString stringWithFormat:@"%.2f%% 满意",my];
    
    double yb = [_model.starCountArr[3] doubleValue] / total*100;
    self.yb.text = [NSString stringWithFormat:@"%.2f%% 一般",yb];
    
    double cp = [_model.starCountArr[4] doubleValue] / total*100;
    self.cp.text = [NSString stringWithFormat:@"%.2f%% 差评",cp]; 
    [self.pie strokePath];
}
@end
